<html>
    <head>
        {php}html_header_show();{/php}
        {php}html_header_show2();{/php}

        {literal} 
        <script language="javascript">

            $(document).ready(function() {
                $('#Submit').on("click", function(e) {
                    e.preventDefault();
                    var tipoexamen = $("#tipoexamen").val();
                    var comentarios = $("#comentarios").val();
                    var tipoExNum = parseInt(tipoexamen);
                    var obj;
                    var result;

                    $.ajax({
                        type: "POST",
                        cache: false,
                        url: 'Handler.php?tipoexamen=' + tipoexamen + '&clean=1',
                        data: '', // all form fields
                        success: function(data) {
                            /*alert(data);*/
                            obj = new ActiveXObject("Integrador.Integrador");

                            switch (tipoExNum) {
                                case 1: //Auscultaciones Cardiacas [estetoscopio]
                                    result = obj.Iniciar_Aplicacion("C:\\Program Files (x86)\\Littmann\\StethAssist\\Littmann StethAssist.exe");
                                    break;
                                case 2: //Auscultaciones Respiratorias [estetoscopio]
                                    result = obj.Iniciar_Aplicacion("C:\\Program Files (x86)\\Littmann\\StethAssist\\Littmann StethAssist.exe");
                                    break;
                                case 3: //Dermatologías [camdermatologica]
                                    result = obj.Iniciar_Aplicacion("C:\\Program Files (x86)\\Firefly\\FireflyPro\\FireflyPro.exe");
                                    break;
                                case 4: //Electrocardiogramas [ecg]
                                    result = obj.Iniciar_Aplicacion("C:\\Cardioline\\Cube\\CMW\\cube.exe");
                                    break;
                                case 5: //Espirometrías [espirometro]
                                    
                                        $.ajax({
                                        type: "POST",
                                        cache: false,
                                        url: 'Handler.php?tipoexamen=' + tipoexamen + '&espirometro=1',
                                        data: '', // all form fields
                                        success: function(data) {
                                            /*alert(data);*/
                                            result = obj.Iniciar_Aplicacion("C:\\MIR\\WinspiroPRO\\winspiroPRO.bat");
                                        } // success
                                    }); // ajax
                                    break;
                                case 6: //Otoscopias [otoscopio]
                                    result = obj.Iniciar_Aplicacion("C:\\Program Files (x86)\\Firefly\\FireflyPro\\FireflyPro.exe");
                                    break;
                            }
                            if (result === true) {
                                if (confirm("¿Ha finalizado correctamente el examen?. En caso afirmativo clic en el boton Aceptar.")) {
                                    $.ajax({
                                        type: "POST",
                                        cache: false,
                                        url: 'Handler.php?tipoexamen=' + tipoexamen + '&comentarios=' + comentarios,
                                        data: '', // all form fields
                                        success: function(data) {
                                            //alert(data);
                                            parent.$.fancybox.close();
                                        } // success
                                    }); // ajax
                                }
                            } else {
                                alert('No existe el programa instalado en este computador. Por favor contacte al Administrador.');
                            }
                        } // success
                    }); // ajax
                }); // click
            });
        </script> 
        {/literal} 

    </head>
    <body style="padding: 0; background: none repeat scroll 0px 0px rgb(249, 249, 249);">
        <div class="borde_normal" style="padding: 0px;"><p><span class="historial_paciente"><i class="icon-dashboard" style="font-size: 1.2em;"></i> {php} echo 'Examen con equ&iacute;po m&eacute;dico'; {/php}</span></p></div>
        <form name="examenes" id="examenes" method="post" action="{$FORM_ACTION}/interface/forms/examenes/save.php">
            <table>
                <tr>
                    <td align="left" style="padding-right: 20px;text-align: right; width: 145px;width: 25%;">{php}echo "Seleccione el tipo de examen:" {/php}</td>
                    <td width="90%">
                        <select name='tipoexamen' id='tipoexamen'>
                            <option value='_blank'><?php xl('Select One', 'e'); ?></option>
                            {php}

                            $cres = sqlStatement("SELECT * FROM `list_options` WHERE list_id = 'Tipos_examen' order by seq asc");
                            while ($crow = sqlFetchArray($cres)) {
                            echo "       <option value='".$crow['seq']."'";
                                                 if( $crow['seq'] == $result['pc_conductid'] ) echo " selected ";
                                                 echo ">" . $crow['title'] . "</option>\n";
                            }

                            {/php}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="left" style="padding-right: 20px;text-align: right; width: 145px;width: 25%;">{php} echo 'Comentarios:'; {/php}</td>
                    <td width="90%">
                        <textarea id="comentarios" name="comentarios" cols="60" rows="4">{$data->get_comentarios()}</textarea>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button id="Submit" class="css_button" name="Submit" type="button"><i class="icon-ok-sign"></i> Iniciar</button>
                        <button id="cancelar" onclick="parent.$.fancybox.close();" class="css_button" type="button"><i class="icon-remove-sign"></i> Cancelar</button>
                    </td>
                </tr>
            </table>
            <input type="hidden" name="id" value="{$data->get_id()}" />
            <input type="hidden" name="pid" value="{$data->get_pid()}">
            <input type="hidden" name="userid" value="{php}$_SESSION['authId']{/php}">
            <input type="hidden" name="activity" value="{$data->get_activity()}">
            <input type="hidden" id="documentid" name="documentid" value="">
            <input type="hidden" name="process" value="true">
        </form>
    </body>
</html>